<template>
  <div class="app-container">
    <div class="formDiv">
      <el-form ref="form" :inline="true" label-width="140px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="医院名称">
              <el-select
                clearable
                @clear="clearfn('hospitalId')"
                filterable
                v-model="params.hospitalId"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in officeOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="提现时间">
              <el-date-picker
                v-model="time"
                type="daterange"
                value-format="yyyy-MM-dd HH:mm:ss"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="审核状态">
              <el-select
                clearable
                @clear="clearfn('auditStatus')"
                filterable
                v-model="params.auditStatus"
                placeholder="请选择"
              >
                <el-option label="全部" :value="null"></el-option>
                <el-option label="待审核" :value="0"></el-option>
                <el-option label="审核通过" :value="1"></el-option>
                <el-option label="审核失败" :value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="审核时间">
              <el-date-picker
                v-model="time1"
                type="daterange"
                value-format="yyyy-MM-dd HH:mm:ss"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-button style="margin-left:30px" type="primary" @click="searchFn">查询</el-button>
             <Exprotcomponent
              :params="params"
              url="/com.mmk.reservation.api.AdminHospitalAccountProvider/1.0.0/hospitalAccountRechargeexport.html"
              type="java"
              permissionJson="AdminHospitalAccountProvider.hospitalAccountRechargeexport"
            ></Exprotcomponent>

            <el-button
              style="margin-left:60px"
              type="primary"
              @click="checkfn()"
              v-if="$store.state.user.permissionJson.indexOf('AdminHospitalAccountProvider.hospitalWithdrawalReview') !=-1"
            >批量审核</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="listDiv">
      <el-table
        :data="tableData"
        class="tableData"
        ref="multipleTable"
        @selection-change="handleSelectionChange"
        style="width: 100%"
      >
        <el-table-column type="selection" width="55" :selectable="selectable"></el-table-column>
        <el-table-column
          type="index"
          label="序号"
          fixed="left"
          align="center"
          :index="table_index"
          width="50"
        ></el-table-column>
        <el-table-column prop="name" label="医院名称" align="center" />
        <el-table-column prop="bankCard" label="提现卡号" align="center" />
        <el-table-column prop="bank" label="开户行" align="center" />
        <el-table-column prop="realName" label="户名" align="center" />

        <el-table-column prop="amount" label="提现金额" align="center" />

        <el-table-column prop="amountAgo" label="账户当前余额" align="center" />
        <el-table-column prop="amountAfter" label="提现后余额" align="center" />
        <el-table-column prop="createdAt" label="提现时间" align="center"></el-table-column>
        <el-table-column prop="rechargeDesc" label="提现说明" align="center" />

        <el-table-column prop="auditStatus" label="审核状态" align="center" />
        <el-table-column prop="auditDesc" label="审核说明" align="center" />
        <el-table-column prop="moneyBank" label="打款银行" align="center"></el-table-column>
        <!-- 新加 -->
        <el-table-column prop="auditAt" label="审核时间" align="center" />
        <el-table-column prop="auditBy" label="审核人" align="center" />
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              v-if="$store.state.user.permissionJson.indexOf('AdminHospitalAccountProvider.hospitalWithdrawalReview') !=-1 && scope.row.auditStatus=='待审核'"
              @click="checkfn(scope.row)"
              type="text"
            >审核</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagesCon">
      <div>
        <el-pagination
          :current-page="params.pageNum"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="params.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
      <el-form ref="form" :rules="rules" :model="form" label-width="80px">
        <el-form-item label="审核结果" prop="auditStatus">
          <el-radio v-model="form.auditStatus" :label="1">审核通过</el-radio>
          <el-radio v-model="form.auditStatus" :label="2">审核失败</el-radio>
        </el-form-item>
        <el-form-item label="打款银行" v-if="form.auditStatus==1" prop="bankCardobj">
         
          <el-select v-model="form.bankCardobj" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.mmkCardNo"
              :label="item.mmkCardBankTitle2"
              :value="item.mmkCardNo"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核说明">
          <el-input v-model="form.auditDesc"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="sure">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { hospitalDropDown } from "@/api/doctorManage";
import { money } from "@/api/financShopCash";
import { exportfile } from "@/api/commjs/exprot";
import {
  hospitalAccountRechargeList,
  hospitalWithdrawalReview
} from "@/api/money";
export default {
  name: "",
  data() {
    return {
      form: {},
      options: [],
      dialogVisible: false,
      time: "",
      total: 0,
      rules: {
        auditStatus: [
          { required: true, message: "请输入审核结果", trigger: "blur" }
        ],
        bankCardobj: [
          { required: true, message: "请选择银行卡", trigger: "blur" }
        ]
      },
      tableData: [{}],
      officeOption: [],
      time1: "",
      multipleSelection: [],
      params: { pageNum: 1, pageSize: 10, type: 1 }
    };
  },
  watch: {
    time(val) {
      this.params.createdAtStart = val ? val[0] : "";
      this.params.createdAtEnd = val ? val[1] : "";
    },
    time1(val) {
      this.params.auditAtStart = val ? val[0] : "";
      this.params.auditAtEnd = val ? val[1] : "";
    }
  },
  created() {
    this.list();
    this.hlist();
    this.bank();
  },
  methods: {
    //导出
    exfun() {
      exportfile(
        "/com.mmk.reservation.api.AdminHospitalAccountProvider/1.0.0/hospitalAccountRechargeexport.html",
        this.params
      );
    },
    //清空
    clearfn(val) {
      if (!this.params[val]) this.params[val] = null;
      console.log(val, this.params[val]);
    },
    // 复选框禁用控制
    selectable(row, index) {
      if (row.auditStatus == "待审核") {
        return true;
      } else {
        return false;
      }
    },
    async bank() {
      //银行卡
      let res = await money();
      if (res.data.code == 0) {
        res.data.data.list.map(res=>{
          res.mmkCardBankTitle2 =  res.mmkCardBankTitle+ res.mmkCardNo.substring(res.mmkCardNo.length-4)
        })
        this.options = res.data.data.list;
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    sure() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (!this.form.id) {
            let arr = [];
            this.multipleSelection.map(res => {
              arr.push(res.id);
            });
            this.form.id = arr;
          }
          if (this.form.bankCardobj) {
            this.options.map(res => {
              if (res.mmkCardNo == this.form.bankCardobj) {
                this.form.bankCard = res.mmkCardNo + " " + res.mmkCardBankTitle;
              }
            });
          }

          console.log(this.form);
          hospitalWithdrawalReview(this.form).then(res => {
            this.$message.warning(res.data.msg);
            if (res.data.code == 0) this.list();
          });
          this.dialogVisible = false;
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    checkfn(datas) {
      console.log(this.multipleSelection);
      if (this.multipleSelection.length == 0 && !datas) {
        this.$message.warning("请勾选选项");
        return;
      }
      this.form = {};
      if (datas) {
        this.form.id = [datas.id];
      }
      this.dialogVisible = true;
    },
    searchFn() {
      this.params.pageNum = 1;
      this.list();
    },
    async list() {
      let res = await hospitalAccountRechargeList(this.params);
      if (res.data.code == 0) {
        this.tableData = res.data.data.list;
        this.total = res.data.data.count;
      }
    },
    hlist() {
      hospitalDropDown().then(res => {
        if (res.data.code == 0) {
          let resData = res.data.data;
          let newData = [];
          resData.forEach(e => {
            newData.push({
              value: e.id + "",
              label: e.name
            });
          });
          newData.unshift({
            value: "",
            label: "全部"
          });
          this.officeOption = newData;
        }
        // console.log(this.officeOption)
      });
    },
    handleSizeChange(val) {
      this.params.pageNum = 1;
      this.params.pageSize = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.params.pageNum = val;
      this.list();
    },
    table_index(index) {
      return (this.params.pageNum - 1) * this.params.pageSize + index + 1;
    }
  }
};
</script>
